//
//  MainNavigationController.m
//  customNavWithRuntime
//
//  Created by azx on 15/6/12.
//  Copyright (c) 2015年 azx. All rights reserved.
//

#import "MainNavigationController.h"

@interface MainNavigationController () <UIGestureRecognizerDelegate>

@end

@implementation MainNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIGestureRecognizer *oldGesture = self.interactivePopGestureRecognizer;
    oldGesture.enabled = NO;
    UIView *gestureView = oldGesture.view;
    
    UIPanGestureRecognizer *newGesture = [[UIPanGestureRecognizer alloc] init];
    newGesture.delegate = self;
    newGesture.maximumNumberOfTouches = 1;
    [gestureView addGestureRecognizer:newGesture];
    
    id gestureRecognizerTarget = [[oldGesture valueForKey:@"_targets"] firstObject];
    id navigationInteractiveTransition = [gestureRecognizerTarget valueForKey:@"_target"];
    SEL handleTransition = NSSelectorFromString(@"handleNavigationTransition:");
    
    [newGesture addTarget:navigationInteractiveTransition action:handleTransition];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    /**
     *  这里有两个条件不允许手势执行，1、当前控制器为根控制器；2、如果这个push、pop动画正在执行（私有属性）
     */
    return self.viewControllers.count != 1 && ![[self valueForKey:@"_isTransitioning"] boolValue];
}

@end
